require 'fastercsv'

class CsTerm
  attr_reader :term, :broader_terms, :top_terms, :used_for, :category
  
  def initialize(row)
    @term, @broader_terms, @top_terms, @used_for, @category = row[1..-1]
    @broader_terms = @broader_terms.split '/' if @broader_terms
    @top_terms = @top_terms.split '/' if @top_terms
    @used_for = @used_for.split '/' if @used_for
  end
end

class CsThesaurus
  def initialize(csvfile)
    @dictionary = {}
    @size = 0
    FasterCSV.foreach(csvfile) do |row|
      term = CsTerm.new row
      @dictionary[term.term] ||= []
      @dictionary[term.term] <<= term
      @size += 1
    end        
  end
  
  def [](key)
    @dictionary[key] ? @dictionary[key] : []
  end

  def size
    @size
  end
  
  def each_pair(&p)
    @dictionary.each_pair(&p)
  end 
end

#thes = CsThesaurus.new(File.dirname(__FILE__) + '/thesaurus_src.csv')
#thes.each_pair do |k, v|
#  v.each do |term|
#    puts term.term
#  end
#end


